#ifndef _AGENTIMPL_H_
#define _AGENTIMPL_H_

#include "stdafx.h"
#include "auth.hpp"
#include "msgbuschannel.hpp"

class CAgentImpl : public IAgent, public IOperationProc, public CMsgbusChannel, public CUnknownImp

{
public:
    CAgentImpl(void);
    virtual ~CAgentImpl(void);

    BEGIN_STDCOM_MAP
    STDCOM_INTERFACE_ENTRY_UNKNOWN_(IAgent)
    STDCOM_INTERFACE_ENTRY(IOperationProc)
    STDCOM_INTERFACE_ENTRY(IAgent)
    END_STDCOM_MAP

public:
    // IAgent
    std_method(SetId)(unsigned int id);
    std_method(Bind)(LPCSTR addr, int len);
    std_method(Close)();
    std_method(Recv)(IBase* pBase);
    std_method(Send)(IBase* pBase);

    // IOperationProc
    std_method(OnComplete)(IBase* pOperation, crtid cid, crterr err);

private:
    std_method(OnConnected)(IBase* pIBase);
    std_method(OnSendSeqed)(IBase* pIBase);
    std_method(OnRecvSeqAcked)(IBase* pIBase);
    std_method(OnSendAcked)(IBase* pIBase);
    std_method(OnRecvHeaded)(IBase* pIBase);
    std_method(OnRecved)(IBase* pIBase);
    std_method(OnSendHeaded)(IBase* pIBase);
    std_method(OnSended)(IBase* pIBase);

private:
    CSemHandle m_sem;
    unsigned int m_id;
    BusProtocol m_bus;
};

#endif
